package com.lingkang.sales.config.auth;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

/**
 * @author linke
 * @date 2020/11/14 23:26
 * @description 自定义403页面
 */
public class AuthenticationAccessDeniedHandler implements AccessDeniedHandler {

  @Override
  public void handle(HttpServletRequest request, HttpServletResponse response,
      AccessDeniedException accessDeniedException) throws IOException, ServletException {
    String url = "/error/403";
    //1.调用HttpServletRequest的getRequestDispatcher()方法，调用时需要传入转发的地址;
    RequestDispatcher requestDispatcher = request.getRequestDispatcher(url);
    //2.调用HttpServletRequest的forward(request,response)方法进行请求的转发;
    requestDispatcher.forward(request, response);
  }
}
